{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n*************************\nText rendering With LaTeX\n*************************\n\nRendering text with LaTeX in Matplotlib.\n\nMatplotlib has the option to use LaTeX to manage all text layout.  This\noption is available with the following backends:\n\n* Agg\n* PS\n* PDF\n\nThe LaTeX option is activated by setting ``text.usetex : True`` in your rc\nsettings.  Text handling with matplotlib's LaTeX support is slower than\nmatplotlib's very capable :doc:`mathtext </tutorials/text/mathtext>`, but is\nmore flexible, since different LaTeX packages (font packages, math packages,\netc.) can be used. The results can be striking, especially when you take care\nto use the same fonts in your figures as in the main document.\n\nMatplotlib's LaTeX support requires a working LaTeX_ installation, dvipng_\n(which may be included with your LaTeX installation), and Ghostscript_\n(GPL Ghostscript 9.0 or later is required). The executables for these\nexternal dependencies must all be located on your :envvar:`PATH`.\n\nThere are a couple of options to mention, which can be changed using\n:doc:`rc settings </tutorials/introductory/customizing>`. Here is an example\nmatplotlibrc file::\n\n  font.family        : serif\n  font.serif         : Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman\n  font.sans-serif    : Helvetica, Avant Garde, Computer Modern Sans serif\n  font.cursive       : Zapf Chancery\n  font.monospace     : Courier, Computer Modern Typewriter\n\n  text.usetex        : true\n\nThe first valid font in each family is the one that will be loaded. If the\nfonts are not specified, the Computer Modern fonts are used by default. All of\nthe other fonts are Adobe fonts. Times and Palatino each have their own\naccompanying math fonts, while the other Adobe serif fonts make use of the\nComputer Modern math fonts. See the PSNFSS_ documentation for more details.\n\nTo use LaTeX and select Helvetica as the default font, without editing\nmatplotlibrc use::\n\n  from matplotlib import rc\n  rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})\n  ## for Palatino and other serif fonts use:\n  #rc('font',**{'family':'serif','serif':['Palatino']})\n  rc('text', usetex=True)\n\nHere is the standard example, `tex_demo.py`:\n\n.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png\n   :target: ../../gallery/text_labels_and_annotations/tex_demo.html\n   :align: center\n   :scale: 50\n\n   TeX Demo\n\nNote that display math mode (``$$ e=mc^2 $$``) is not supported, but adding the\ncommand ``\\displaystyle``, as in `tex_demo.py`, will produce the same\nresults.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>Certain characters require special escaping in TeX, such as::\n\n     # $ % & ~ _ ^ \\ { } \\( \\) \\[ \\]\n\n   Therefore, these characters will behave differently depending on\n   the rcParam ``text.usetex`` flag.</p></div>\n\n\nusetex with unicode\n===================\n\nIt is also possible to use unicode strings with the LaTeX text manager, here is\nan example taken from `tex_demo.py`. The axis labels include Unicode text:\n\n.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png\n   :target: ../../gallery/text_labels_and_annotations/tex_demo.html\n   :align: center\n   :scale: 50\n\n   TeX Unicode Demo\n\n\nPostscript options\n==================\n\nIn order to produce encapsulated postscript files that can be embedded in a new\nLaTeX document, the default behavior of matplotlib is to distill the output,\nwhich removes some postscript operators used by LaTeX that are illegal in an\neps file. This step produces results which may be unacceptable to some users,\nbecause the text is coarsely rasterized and converted to bitmaps, which are not\nscalable like standard postscript, and the text is not searchable. One\nworkaround is to set ``ps.distiller.res`` to a higher value (perhaps 6000)\nin your rc settings, which will produce larger files but may look better and\nscale reasonably. A better workaround, which requires Poppler_ or Xpdf_, can be\nactivated by changing the ``ps.usedistiller`` rc setting to ``xpdf``. This\nalternative produces postscript without rasterizing text, so it scales\nproperly, can be edited in Adobe Illustrator, and searched text in pdf\ndocuments.\n\n\nPossible hangups\n================\n\n* On Windows, the :envvar:`PATH` environment variable may need to be modified\n  to include the directories containing the latex, dvipng and ghostscript\n  executables. See `environment-variables` and\n  `setting-windows-environment-variables` for details.\n\n* Using MiKTeX with Computer Modern fonts, if you get odd \\*Agg and PNG\n  results, go to MiKTeX/Options and update your format files\n\n* On Ubuntu and Gentoo, the base texlive install does not ship with\n  the type1cm package. You may need to install some of the extra\n  packages to get all the goodies that come bundled with other latex\n  distributions.\n\n* Some progress has been made so matplotlib uses the dvi files\n  directly for text layout. This allows latex to be used for text\n  layout with the pdf and svg backends, as well as the \\*Agg and PS\n  backends. In the future, a latex installation may be the only\n  external dependency.\n\n\nTroubleshooting\n===============\n\n* Try deleting your :file:`.matplotlib/tex.cache` directory. If you don't know\n  where to find :file:`.matplotlib`, see `locating-matplotlib-config-dir`.\n\n* Make sure LaTeX, dvipng and ghostscript are each working and on your\n  :envvar:`PATH`.\n\n* Make sure what you are trying to do is possible in a LaTeX document,\n  that your LaTeX syntax is valid and that you are using raw strings\n  if necessary to avoid unintended escape sequences.\n\n* Most problems reported on the mailing list have been cleared up by\n  upgrading Ghostscript_. If possible, please try upgrading to the\n  latest release before reporting problems to the list.\n\n* The ``text.latex.preamble`` rc setting is not officially supported. This\n  option provides lots of flexibility, and lots of ways to cause\n  problems. Please disable this option before reporting problems to\n  the mailing list.\n\n* If you still need help, please see `reporting-problems`\n\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
